<template>
	<view>
		<image src="../../static/login/top3.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">专业代驾 服务第一</text>
		</view>
		<button class="btn" @tap="wxLogin()">司机登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>


export default {
	data() {
		return {};
	},
	methods: {
    toRegisterPage(){
      uni.navigateTo({
        url: '../register/register',
      })
    },
    wxLogin(){
      var _this = this
      wx.login({
        success(res){
          if (res.code){
            var data ={
              code: res.code,
              type: 1
            }
            _this.post("/uaa/manager/login/login",data,res=>{
              if(res.data.success){
                console.log(res)
                uni.setStorageSync("satoken",res.data.data.token);
                uni.setStorageSync("avatar",res.data.data.avatar);
                uni.setStorageSync("nickName",res.data.data.nickName);
                uni.setStorageSync("phone",res.data.data.phone);
                uni.setStorageSync("id",res.data.data.id);
                uni.showToast({ icon:"success", title:"登录成功" })
                //跳转工作台页面
                setTimeout(()=>{
                  uni.switchTab({
                    url:"../workbench/workbench"
                  })
                },2000)
              }else{
                uni.showToast({
                  title: res.data.message,
                  icon: "error",
                })
              }
            })
          }else{
            console.log("登录失败")
          }
        }
      })
    }
	},
	onLoad: function() {
	}
};
</script>

<style lang="less">
@import url('login.less');
</style>
